package Save.JavaUtil.Json;

import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

/**
 * 
 * @author jackleijie
 * 引入一下配置即可使用
 *  <dependency>
		<groupId>net.sf.flexjson</groupId>
		<artifactId>flexjson</artifactId>
		<version>2.0</version>
	</dependency>
	<dependency>
		<groupId>org.codehaus.jackson</groupId>
		<artifactId>jackson-core-asl</artifactId>
		<version>1.9.13</version>
	</dependency>
	<dependency>
		<groupId>org.codehaus.jackson</groupId>
		<artifactId>jackson-mapper-asl</artifactId>
		<version>1.9.13</version>
	</dependency>
	<dependency>
		<groupId>net.sf.json-lib</groupId>
		<artifactId>json-lib</artifactId>
		<version>2.4</version>
		<classifier>jdk15</classifier>
	</dependency>
	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
		<version>2.8.0</version>
	</dependency>
 *
 */
public class ObjectToJson {
	//将list结果转换为json
	public String CustomerListToJson(List<?> list){
		JSONArray json = JSONArray.fromObject(list);
		String Jsonmsg = json.toString();
		return Jsonmsg;
	}
	
	//将list<map>结果转化为json
	public String MapToJson(List<Map<String,Object>> list,String pagesum,String pagesize,String pagebay){
		JSONArray json = JSONArray.fromObject(list);
		String Jsonmsg = "{\"itens\":"+json.toString()+",\"total\":"+pagesum+",\"num\":"+pagesize+",\"topage\":"+pagebay+"}";
		return Jsonmsg;
	}
	//将list<map>结果转化为json
	public String MapToJsonNotPage(List<Map<String,Object>> list){
		JSONArray json = JSONArray.fromObject(list);
		String Jsonmsg = json.toString();
		return Jsonmsg;
	}

}
